/*
 * ksCatalogAtomBlockWriter.h
 *
 *  Created on: 2011-8-13
 *      Author: wangchao
 */

#ifndef KSCATALOGATOMBLOCK_H_
#define KSCATALOGATOMBLOCK_H_

#include "ksAtomBlockWriter.h"
#include <vector>

class ksBlockEntry;
/*目录条目*/
class ksCatalogEntry
{
public:
    enum CatalogType
    {
        //
        EVolume = 0, //卷
        EChapter, //章节
        EEnd
    };
public:
    unsigned char _type;
    std::string _title;
    unsigned int _offset;
    std::string _resource;
    int _resourceId;
public:
    void save(std::ofstream & out);
    unsigned int dataSize();
};
class ksCatalogAtomBlockWriter: public ksAtomBlockWriter
{
public:
    ksCatalogAtomBlockWriter();
    virtual ~ksCatalogAtomBlockWriter();
protected:
    std::vector<ksCatalogEntry*> _entries;
public:
    unsigned int blockLength();
    void setData(unsigned char *data, unsigned int length);
    void save(std::ofstream & out);
public:
    void updateResourceID( const std::string& resource, int resourceId );
    void updateEntryOffset( const ksBlockEntry& entry, int offsetInFile );
};

#endif /* KSCATALOGATOMBLOCK_H_ */
